package Classes.GameDatas // ActionScript file
{
	import Classes.GameErrors.GameError;
	import Classes.GameUtils.GD_deal;
	import Classes.GameUtils.GU_DealPlaySpeed;
	import Classes.GameUtils.GU_Sound;
	import Classes.GameUtils.GU_dealBgSound;
	import Classes.GameUtils.GU_dealPower;
	import Classes.GameUtils.GU_dealSharePreWin;
	import Classes.GameUtils.GU_dealWeapon;
	import Classes.GameViews.GV_Map;
	import Classes.GameViews.ViewDisplayers.MapTargets.MapMoveTargets.MMT_Character;
	import Classes.GameViews.ViewPanels.VP_DayRewardUI;
	import Classes.GameViews.ViewPanels.VP_Main;
	import Classes.GameViews.ViewPanels.VP_OpenWinView;
	import Classes.GameViews.ViewPanels.VP_errorPanel;
	import Classes.GameViews.ViewPanels.VP_getItems;
	import Classes.GameViews.ViewPanels.VP_message;
	import Classes.GameViews.ViewPanels.ViewPanel;
	import Classes.GameViews.ViewScenes.VS_Main;
	import Classes.Managers.M_BaseCartoons;
	import Classes.Managers.M_Communication;
	import Classes.Managers.M_ConfigData;
	import Classes.staticinfo.Language;
	import Classes.staticinfo.PlatformInfo;
	import Classes.staticinfo.StaticInfo;
	
	import UIComponents.FlatInfo;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.system.ApplicationDomain;
	import flash.utils.Timer;
	
	/**
	 *玩家信息类
	 * @author 葛增文
	 *
	 */
	public class GD_Player extends GameData
	{
		private static var _instance:GD_Player; /*静态引用*/
		
		private var _closeTimerLister:Boolean=false; /*监听 行动力的时间  是否关闭*/
		
		private var _powerTime:Number; /*剩余恢复体力的时间*/
		
		private var _playerID:Number; /*玩家ID*/
		
		private var _playerName:String; /*玩家名字*/
		private var _playerViewID:String; /*玩家头像ID*/
		private var _playerJob:int; /*玩家职业*/
		private var _playerSex:String="0"; /*玩家性别*/
		private var _playerLv:int=-1; /*玩家等级*/
		private var _playerExp:Number; /*玩家经验*/
		private var _money:Number; /*玩家金钱*/
		private var _gold:Number; /*玩家人民币代币*/
		private var _actPoint:int; /*行动点数*/
		private var _centerLv:int; /*主建筑等级*/
		private var _havenState:Boolean; /*避难所状态*/
		private var _wallLv:int; /*围墙等级*/
		
		private var _storeBuildings:Object; /*仓库建筑存储器*/
		private var _items:Object=new Object(); /*物品存储器*/
		
		private var _missions:Object=new Object(); /*任务存储器*/
		private var _collectMissionArr:Array=new Array(); /*收藏物品存储器*/
		
		private var _weapons:Object=new Object(); /*武器存储器*/
		private var _selectWeapons:Object=new Object(); /*用来装备的武器*/
		private var _addNewWeapons:Object=new Object();/*用来装载新武器的 对象 用来实现  得到新武器时 弹框的问题*/
		
		private var _mapData:GD_Map;
		private var _character:GD_Character;
		
		private var _playerLife:int; /*健康点数*/
		
		private var _playerCurrentMaxExp:Number; /*当前玩家经验上限 */
		
		private var _playCurrentMaxActPoint:int; /*玩家当前行动了上限 */
		
		private var _currentWeapon:String; /*玩家当前所持武器*/
		
		private var _friendAct:Number;/*在好友家的友情行动力*/
		
		private var _speed:int;//玩家初始化速度
		
		private var _speedTime:int;//加速影响的时间
		
		private var _attRange:Number;/*人物攻击的范围*/
		private var _attactType:String;/*人物攻击方式*/
		
		private var _isNew:int;/*是否是新手  0老玩家  1是新手*/
		
		private var _qqVipId:int;
		
		private var _isGetNewqqGift:int;
		private var _isGetDayqqGift:int;
		
		private var _exchangeBuildItemNum:int;
		
		private var _myBuildObj:Object=new Object();/*我的建筑对象  支持我在好友家时  任务拥有建筑的功能*/
		
		private var _onlineMinute:int;/*在线礼包领取时间 如果为0  则领取次数完毕  其余的都为倒计时时间 */
		
		private var _playPower:String;/*权限字符串*/
		
		private var _playPowerObj:Object=new Object();
		
		/**
		 * 1表示可以领取，0表示不可以领取  每日登陆礼包
		 */		
		public var dayRewardStatue:int=0;
		
		/**
		 * 连续登陆的天数 
		 */		
		public var dayRewardDays:int=0;
		
		
		/**
		 * 玩家当前的总行动力值，用来进行掉落的比较 行动力
		 */
		public static var playerNowAction:int;
		/**
		 * 玩家当前的总经验，用来进行掉落的比较 经验
		 */
		public static var playNowExp:Number;
		/**
		 * 玩家当前的总金币，用来进行掉落的比较 金币
		 */
		public static var playNowMoney:Number;
		/**
		 * 玩家当前的总O币，用来进行掉落的比较 O币
		 */
		public static var playNowOMoney:Number;
		
		
		/**
		 *q点消耗值 
		 */
		public  var playerConsume:Number	=	0;
		
		public function GD_Player():void
		{
			this.init();
		}
		
		private function init():void
		{
			
		}
		
		/**
		 *初始化设定玩家ID
		 * @param playerID 玩家ID
		 */
		public function setPlayerID(playerID:Number):void
		{
			this._playerID=playerID;
			M_Communication.instance.send(11001);
		}
		
		/**
		 * 发送过去玩家被雇佣好像列表 
		 */		
		public function sendGetHiredFriendList():void
		{
			M_Communication.instance.send(124005);
		}
		
		/**
		 *初始化设定玩家的数据
		 * @param dataObj 玩家数据对象
		 *
		 */
		public function setPlayerData(dataObj:Object):void
		{
			this._wallLv=dataObj.buildLevel;
			this.playPower=dataObj.playPower;
			this.setBaseData(dataObj.baseData);
			this.initItems(dataObj.itemsAry);
			this.setStoreBuildings(dataObj.storeBuildingsAry);
			
			this._mapData=GD_Map.creat(dataObj.wallsAry, dataObj.buildingsAry, dataObj.zombiesAry, dataObj.sickMansAry, dataObj.sundriesAry);
			
			this._character=GD_Character.creat({job: this.playerJob, life: dataObj.baseData.playerLife});
			this._character.characterState=0;
			this._character.characterId=this.playerID;
			this._character.gd_characterPlay=this;
			this._character.controlEnabled=true;
			this._character.playSpeed=this.speed;
			
			if(this.isNew==1)//新手时用来备用的
			{
				this.tmpCharater=GD_Character.creat({job: this.playerJob, life: dataObj.baseData.playerLife});
				this.tmpCharater.characterState=0;
				//				this.tmpCharater.characterId=this.playerID;
				this.tmpCharater.gd_characterPlay=this;
				this.tmpCharater.controlEnabled=true;
			}
			
			this.initSelectWeapons(dataObj.weaponAry);
			
			M_BaseCartoons.instance.needLoadBaseCartoon(this.jobCartoonType, baseCartoonLoadOver);
			//初始化任务
			this.setMissions(dataObj.missionsAry);
			
			GD_AllFriends.instance.createFriend(dataObj.friendsAry);
			
			//消息系统
			if(dataObj.hasOwnProperty("messagesAry")){
				VP_message.instance.cleanMessage();
				VP_message.instance.addMessageObjectFromAry(dataObj.messagesAry);
			}
			
			
			noNew=true;
		}
		public var noNew:Boolean=false;
		
		private var tmpCartoonType:String;
		private var tmpCharater:GD_Character;
		private function baseCartoonLoadOver(cartoonType:String):void
		{
			tmpCartoonType=cartoonType;
			if(this.isNew==1)
			{
				M_BaseCartoons.instance.needLoadBaseCartoon("character_boy1", baseNewPlayerLoadOver);
			}else{
				ZombieTown.instance.loadOverCallBackFun(this.isNew);
			}
			
		}
		private var tmpNewPlayerCartoonType:String;
		private function baseNewPlayerLoadOver(cartoonType:String):void
		{
			tmpNewPlayerCartoonType=cartoonType;
			ZombieTown.instance.loadOverCallBackFun(this.isNew);
		}
		
		/**
		 *初始化设定玩家基本数据
		 * @param dataObj 基本数据对象
		 *
		 */
		private function setBaseData(dataObj:Object):void
		{
			for (var k:String in dataObj)
			{
				if ("playerLife" == k)
				{
					this["_" + k]=dataObj[k];
				}
				else
				{
					this[k]=dataObj[k];
				}
				
				if (k == "actPoint")
				{
					GD_Player.playerNowAction=dataObj[k];
				}
			}
		}
		
		/**
		 *初始化设定玩家仓库建筑数据
		 * @param dataObj
		 *
		 */
		private function setStoreBuildings(storeBuildingsAry:Array):void
		{
			this._storeBuildings=new Object;
			for each (var storeBuildingObj:Object in storeBuildingsAry)
			{
				var buildingItem:GD_BuildingItem=GD_BuildingItem.creat({buildingItemType: storeBuildingObj.buildingType, buildingItemNum: storeBuildingObj.buildingNum});
				this.storeBuildings[buildingItem.buildingItemType]=buildingItem;
			}
		}
		
		/**
		 * 在仓库中是否拥有此建筑  
		 * @param buildingID 功能ID
		 * @return  建筑的 ID  不是功能ID  返回0就代表没有
		 * 
		 */		
		public function hasbuildInStroeByFunid(buildingID:Number):Number
		{
			var tmpb:Number=0;
			for each (var tb:GD_BuildingItem in this.storeBuildings)
			{
				if (buildingID == tb.buildingType)
				{
					tmpb=tb.buildingItemType;
					break;
				}
			}
			return tmpb;
		}
		
		/**
		 * 初始化玩家装备武器
		 * @param arr
		 */
		private function initSelectWeapons(arr:Array):void
		{
			for each (var weaponObj:Object in arr)
			{
				var _weanId:Number=weaponObj.weaponId;
				var weapon:GD_Weapon=GD_Weapon.creat({itemType: _weanId, itemNum: weaponObj.weaponCount});
				this.selectWeapons[_weanId]=weapon;
			}
		}
		
		/**
		 * 根据类型 初始化数据
		 * @param arr
		 *
		 */
		private function initItems(arr:Array):void
		{
			for each (var itemData:Object in arr)
			{
				var _itemType:Number=itemData.itemType;
				var itemKind:String=GD_deal.instance.reutrnType(_itemType);
				switch (itemKind)
				{
					case StaticInfo.ITEM_TYPE:
						var item:GD_Item=GD_Item.creat({itemType: _itemType, itemNum: itemData.itemNum});
						this.items[_itemType]=item;
						break;
					case StaticInfo.WEAPON_TYPE: //武器 除去  已经装备好的武器
						var weapon:GD_Weapon=GD_Weapon.creat({itemType: _itemType, itemNum: itemData.itemNum});
						this.weapons[_itemType]=weapon;
						break;
				}
				//购买建筑的物品
				if(_itemType==M_ConfigData.instance.exchangeItemId)
				{
					this.exchangeBuildItemNum=Number(itemData.itemNum);
				}
			}
		}
		
		
		/**
		 *初始化玩家的任务数据
		 * @param missionsAry
		 *
		 */
		private function setMissions(missionsAry:Array):void
		{
			this.addMissions(missionsAry);
		}
		
		/**
		 * 增加任务
		 * @param missionsAry
		 */
		public function addMissions(missionsAry:Array):void
		{
			if (null == missionsAry || missionsAry.length < 1)
			{
				collectItemNumChange();
				return;
			}
			for each (var missionData:Object in missionsAry)
			{
				var mission:GD_Mission=GD_Mission.creat({missionID: missionData.missionID,missionStatue:missionData.missionStatue, missionType: missionData.missionType, countsAry: missionData.countsAry});
				this._missions[missionData.missionID]=mission;
				initMissCurrentValue(mission);
			}
			collectItemNumChange();
			this.missionsHaveChange();
		}
		
		public function initMissCurrentValue(mission:GD_Mission):void
		{
			for each(var count:Object in mission.conditionCounts)
			{
				switch(count.countThirdType)
				{
					case 101://提交金币
						mission.setMissionNowValue(count.countType,this.money,false);
						break;
					case 102://提交物品
					case 103://拥有物品
						var misItemCount:Number=GD_deal.instance.getNumByObjId(count.needItemId);
						mission.setMissionNowValue(count.countType,misItemCount,false);
						break;
					case 104://拥有建筑
						var tmpBuildFunId:Number=count.needItemId;
						var tmpBuildGreed:int=count.zt_task_elf_2;
						var buildId:Number=GD_Building_Func.buildingsConfigObj[tmpBuildFunId].lvData[tmpBuildGreed].buildingItemType;
						//						trace("renwu="+mission.missionType+" tmpBuildFunId= "+tmpBuildFunId +" buildId= "+buildId)
						var misBuildCount:Number=GD_deal.instance.getNumByObjId(buildId);
						mission.setMissionNowValue(count.countType,misBuildCount,false);
						break;
					case 105://达到土地等级
						mission.setMissionNowValue(count.countType,this.wallLv,false);
						break;
				}
			}
		}
		
		/**
		 *  由前台的计数的任务 104(拥有建筑) 
		 * @param currentNum
		 * @param buildId
		 * @param missionType
		 */		
		public function changeBuildMiss(currentNum:Number,buildId:Number,missionType:int=104):void
		{
			//功能ID
			var zt_fun_id:Number=GD_BuildingItem.buildingItemsConfigObj[buildId].zt_func_id;
			var zt_current_Lv:int=GD_BuildingItem.buildingItemsConfigObj[buildId].zt_func_greade;
			for each (var mis:GD_Mission in this._missions)
			{
				if (mis.missionType != 21)
				{
					//循环遍历任务的需求列表  && itemID == mis.getNeedItemId()
					for each(var count:Object in mis.conditionCounts)
					{
						if( count.countThirdType == missionType && zt_fun_id==count.needItemId && zt_current_Lv>=count.zt_task_elf_2)
						{
							mis.setMissionNowValue(count.countType, currentNum);
							missionsHaveChange();
						}
					}
				}
			}
			
		}
		
		
		/**
		 * 由前台的计数的任务(101 102 103 105) 
		 * @param currentNum 当前任务完成值
		 * @param missionType 任务类型 101(jb) 102 103(item) 105(达到土地等级)
		 * @param itemID 任务ID
		 */		
		public function changeMIssions(currentNum:Number, missionType:String, itemID:Number=0):void
		{
			var commArr:Array=missionType.split(",");
			if(!commArr || commArr.length<1)return;
			for each (var mis:GD_Mission in this._missions)
			{
				if (itemID == 0)
				{
					if (mis.missionType != 21)
					{
						for each(var count2:Object in mis.conditionCounts)
						{
							for(var i:int=0;i<commArr.length;i++)
							{
								if( count2.countThirdType == commArr[i])
								{
									mis.setMissionNowValue(count2.countType, currentNum);
									//								missionsHaveChange();
								}
							}
							
						}
					}
				}
				else
				{
					if (mis.missionType != 21)
					{
						//循环遍历任务的需求列表  && itemID == mis.getNeedItemId()
						for each(var count:Object in mis.conditionCounts)
						{
							for(var j:int=0;j<commArr.length;j++)
							{
								if( count.countThirdType == commArr[j] && itemID==count.needItemId)
								{
									mis.setMissionNowValue(count.countType, currentNum);
									//								missionsHaveChange();
								}
							}
						}
					}
				}
				
			}
			missionsHaveChange();
		}
		
		
		/**
		 * 触发任务改变的通知
		 */
		public function missionsHaveChange():void
		{
			this.touchObserve("missions");
		}
		
		/**
		 *  任务计数器改变  ,即任务条件完成的次数改变
		 * @param misObj
		 */
		public function setMissionNowValue(misObj:Object):void
		{
			if(null==this._missions[misObj.missionID])
			{
				return;
			}
			((this._missions[misObj.missionID]) as GD_Mission).setMissionNowValue(misObj.countSerial, misObj.value);
		}
		
		/**
		 * 任务完成；从 已有的任务列表中删除任务
		 * @param deleteObj
		 */
		public function deleteMission(deleteObj:Object):void
		{
			var isRefreshMisFlag:Boolean=(this._missions[deleteObj.missionID] as GD_Mission).taskStyle==10?false:true;
			delete this._missions[deleteObj.missionID];
			if(isRefreshMisFlag)
			{
				this.missionsHaveChange();
				if(PlatformInfo.instance.loginMissionShareCount<M_ConfigData.instance.missionShareNum)
				{
					PlatformInfo.instance.loginMissionShareCount++;
					GU_dealSharePreWin.instance.haldSharePreFun(12200);
				}else{
					VP_errorPanel.instance.setErrorMessage(Language.successMsg);
					VP_errorPanel.instance.enterFrame();
				}
				
			}
		}
		
		public function canNotFinishMission():void
		{
			this.touchObserve(StaticInfo.CAN_NOT_FINISH_MISSION);
		}
		
		//播放音乐
		public function playGameMusic():void
		{
			GU_dealBgSound.instance.isCanPalyMusic=true;
			
			//弹出对话框，该对话框出现条件，若玩家等级为1经验为0则弹出一次0
			if(this.playerLv==1 && this.playerExp==0 && this.missions[11000001]  && (this.missions[11000001] as GD_Mission).missionStatue==0)
			{
				M_Communication.instance.send(12201,{missionID:11000001,statue:0});
			}
			GU_dealPower.instance.initNewGuide();
			
			this.character.view.actionLocked=false;//解锁玩家
		}
		
		/**
		 *创建自己的家园
		 *
		 */
		public function creatMyHome():void
		{
			this.touchObserve("QQVip");
			this.sendGetHiredFriendList();
			
			if(this.isNew==1)
			{
				this.playerSex="1";
				this.tmpCharater.view.setBaseCartoonsType(this.tmpNewPlayerCartoonType);
				tmpNewPlayerCartoonType="";
				
			}
			if(this.isNew==1)
			{
				this.playerSex="0";
			}
			this.character.view.setBaseCartoonsType(tmpCartoonType);
			this.character.view.actionLocked=true;//用来 控制刚进入游戏不被僵尸打死
			tmpCartoonType="";
			
			VS_Main.instance.open();
			this.mapData.creatMap();
			GV_Map.instance.creatCharacter(this.character, true);
			this.tweenCenter();
			
			if(this.dayRewardStatue==1 && this.isNew==0 &&  this.playPowerObj[10000215])
			{
				VP_DayRewardUI.instance.open(this.dayRewardDays);
			}else if(this.dayRewardStatue==0 && this.isNew==0 && this.dayRewardDays>0 && this.playPowerObj[10000215])
			{
				addPlayershuxing();
			}
			
			ViewPanel.openNumber=0;
		}
		
		/**
		 * 每日礼包玩家属性增加 
		 */		
		public function addPlayershuxing():void
		{
			var arr:Array=M_ConfigData.instance.dayRewardItems.split(",");
			var tmpDays:int=this.dayRewardDays>=4?4:this.dayRewardDays;
			for(var i:int=0;i<tmpDays;i++)
			{
				var tmpArr:Array=arr[i].toString().split("|");;
				switch(int(tmpArr[0]))
				{
					case 2:// 最大血量
						this.character.lifeMax+=int(tmpArr[1]);
						var countPic1:DisplayObject=new (ApplicationDomain.currentDomain.getDefinition("addLifeValue") as Class);
						countPic1.width=27;
						countPic1.height=27;
						VP_Main.instance.setPlayerEle3(countPic1);
						break;
					case 3:
						//						//速度
						//						this.character.view.speed=this.character.view.speed+int(tmpArr[1]);
						var countPic:DisplayObject=new (ApplicationDomain.currentDomain.getDefinition("addSpeed") as Class);
						countPic.width=27;
						countPic.height=27;
						VP_Main.instance.setPlayEle1(countPic);
						break;
				}
			}
		}
		
		public function createNewPlayerCharacter(sex:String,weaponid:String):void
		{
			var weapon:GD_Weapon=GD_Weapon.creat({itemType: weaponid, itemNum: 1});
			this.selectWeapons[weaponid]=weapon;
			GD_Weapon.defaultWeapon=Number(weaponid);
			this.playerSex=sex;
			if(sex=="0")
			{
				this.currentWeapon=weaponid;
				this.character.job=int(weaponid);
			}else{
				//this.character.view.removeSign=1;
				this.character.release();
				this._character=null;
				
				this._character=this.tmpCharater;
				this._character.characterId=this.playerID;
				//				this._character.view.setBaseCartoonsType(this.tmpNewPlayerCartoonType);
				//				tmpNewPlayerCartoonType="";
				
				GV_Map.instance.creatCharacter(this.character, true);
				this.tweenCenter();
				this.character.job=int(weaponid);
				this.currentWeapon=weaponid;
			}
			this.character.view.actionLocked=true;//用来 控制刚进入游戏不被僵尸打死
			this.touchObserve("addWeaponToEquipmentArea");
		}
		
		/**
		 * 把屏幕定到 人物位置 
		 */		
		public function tweenCenter():void
		{
			if(null==GV_Map.instance.controlTarget)return;
			try{
				GV_Map.instance.y=-((GV_Map.instance.controlTarget as Sprite).y+GV_Map.instance.layerMapTargets.y)+GV_Map.instance.stage.stageWidth/2;
				GV_Map.instance.x=-((GV_Map.instance.controlTarget as Sprite).x+GV_Map.instance.layerMapTargets.x)+GV_Map.instance.stage.stageHeight/2;
			}catch(error:GameError)
			{
				//				throw new GameError("定位控制对象失败")
			}				
		}
		
		/**
		 *使用某种攻击手段
		 * @param attType 攻击类型
		 * @retun 伤害
		 *
		 */
		private function useAttType(attType:int):int
		{
			return 1;
		}
		
		/**
		 *创建掉落奖励
		 * @param dropObj
		 *
		 */
		public function creatDropRewards(rewardsObj:Object):void
		{
			if(null==rewardsObj)return;
			/**打僵尸 是根据 dropTargetPar 来掉落到哪个僵尸身上      而-1类型则根据  dropTargetUser 来确定掉落到哪个对象身上*/
			switch (rewardsObj.dropTargetType)
			{
				case "201": //僵尸掉落
					var zombie:GD_Zombie=GV_Map.instance.mapData.getZombieByID(rewardsObj.dropTargetPar);
					zombie.view.creatRewards(rewardsObj.dropAry as Array);
					break;
				case "-1": //玩家掉落  连击暂时用的也是-1)
					if(null==rewardsObj.dropTargetUser || 0==rewardsObj.dropTargetUser) //如果没有返回对象 则奖励掉入 正在被控制的对象身上
					{
						(GV_Map.instance.controlTarget as MMT_Character).creatRewards(rewardsObj.dropAry as Array);
					}else{
						GV_Map.instance.getPlayerControlTagetById(rewardsObj.dropTargetUser).creatRewards(rewardsObj.dropAry as Array);
						//						MMT_Character.instance.creatRewards(rewardsObj.dropAry as Array);
					}
					break;
			}
			
			GU_Sound.instance.playCommSound("System_Drop");
		}
		
		/**
		 *僵尸血量变化
		 * @param changedObj
		 *
		 */
		public function zombieLifeChanged(changedObj:Object):void
		{
			
			var zombie:GD_Zombie=GV_Map.instance.mapData.getZombieByID(changedObj.zombieID);
			zombie.lifeChanged(changedObj.value);
		}
		
		/**
		 *仓库建筑道具数量变化
		 * @param changedObj
		 *
		 */
		public function storeBuildingNumChanged(changedObj:Object):void
		{
			var buildingItem:GD_BuildingItem=this.getBuildingItemByType(changedObj.buildingItemType);
			if (!buildingItem)
			{
				buildingItem=GD_BuildingItem.creat({buildingItemType: changedObj.buildingItemType, buildingItemNum: changedObj.buildingItemNum});
				this.storeBuildings[changedObj.buildingItemType]=buildingItem;
				this.touchObserve("storeBuildingItems");
			}
			else
			{
				var oldNum:int=buildingItem.buildingItemNum;
				buildingItem.buildingItemNum=changedObj.value;
				if (!oldNum || !buildingItem.buildingItemNum)
					this.touchObserve("storeBuildingItems");
			}
		}
		
		
		
		/**
		 * 道具数量变化
		 * @param changedObj
		 */
		public function itemNumChanged(changedObj:Object):void
		{
			var isAdd:Boolean=true;//是否是加数量
			var _itemType:Number=changedObj.itemType;
			var itemKind:String=GD_deal.instance.reutrnType(_itemType);
			switch (itemKind)
			{
				case StaticInfo.ITEM_TYPE: //物品
					var item:GD_Item=this.getItemByType(_itemType);
					if (!item)
					{
						item=GD_Item.creat({itemType: _itemType, itemNum: changedObj.value});
						this.items[_itemType]=item;
						this.touchObserve("items");
					}
					else
					{
						if(item.itemNumber>changedObj.value)isAdd=false;
						item.itemNumber=changedObj.value;
						if (!item.itemNumber)
							this.touchObserve("items");
					}
					collectItemNumChange();
					
					if(isAdd)
						VP_getItems.instance.showGetItem(item.itemId);								//显示获得的物品
					
					break;
				case StaticInfo.WEAPON_TYPE: //武器    
					//没有装备的所有武器
					var weapon:GD_Weapon=this.getWeaponByType(_itemType);
					//已经装备好的武器
					var xuanqWeapons:GD_Weapon=this.getCurrentWeaponByType(_itemType);
					if (!weapon && !xuanqWeapons)
					{
						weapon=GD_Weapon.creat({itemType: _itemType, itemNum: changedObj.value});
						this.weapons[_itemType]=weapon;
						FlatInfo.newWeaponObj[_itemType]=_itemType;
						this.addNewWeapons[_itemType]=_itemType;
//						GU_dealWeapon.instance.hanldNewWeapon(weapon);
						GU_dealWeapon.instance.addTxToWeaponbuild();
					}
					else if(weapon)
					{
						weapon.itemNumber=changedObj.value;
					}else if (xuanqWeapons){
						xuanqWeapons.itemNumber=changedObj.value;
					}
					this.touchObserve(StaticInfo.WEAPON_NUMBER_CHANGE);
					break;
			}
		}
		
		/**
		 * 收藏物品数量的改变
		 */
		public function collectItemNumChange():void
		{
			this._collectMissionArr=GD_Mission_Collection.creatAllCollectionMissions();
			this.touchObserve(StaticInfo.COLLECT_ITEM_CHANGE);
		}
		
		/**
		 *根据物品类型获得物品数据
		 * @param type
		 * @return
		 *
		 */
		public function getItemByType(type:Number):GD_Item
		{
			return this.items[type] as GD_Item;
		}
		
		/**
		 * 根据物品类型获得武器
		 * @param type
		 * @return
		 */
		public function getWeaponByType(type:Number):GD_Weapon
		{
			return this.weapons[type] as GD_Weapon;
		}
		
		/**
		 * 根据物品Id 返回 已经装备好的武器
		 * @param type
		 * @return 
		 * 
		 */		
		public function getCurrentWeaponByType(type:Number):GD_Weapon
		{
			return this.selectWeapons[type] as GD_Weapon;
		}
		
		/**
		 *根据建筑道具类型获得建筑道具数据
		 * @param type
		 * @return
		 *
		 */
		public function getBuildingItemByType(type:Number):GD_BuildingItem
		{
			return this.storeBuildings[type] as GD_BuildingItem;
		}
		
		/*getter & setter*/
		public static function get instance():GD_Player
		{
			if (!_instance)
				_instance=new GD_Player;
			return _instance;
		}
		
		public function get playerID():Number
		{
			return _playerID;
		}
		
		public function get playerName():String
		{
			return _playerName;
		}
		
		public function get playerJob():int
		{
			return _playerJob;
		}
		
		/**
		 * 玩家的男或者女的模型   如果是新手  则刚开始初始化时默认是女的
		 * @return
		 */
		public function get jobCartoonType():String
		{
			var paperType:String="character_girl1";
			if (this.playerSex == "1")
			{
				paperType="character_boy1";
			}
			if(this.isNew==1)//如果是新手则给一个女孩的裸模
			{
				paperType="character_girl1";
			}
			return paperType;
		}
		
		/**
		 * （1男，0女）
		 * @return
		 */
		public function get playerSex():String
		{
			return _playerSex;
		}
		
		public function get playerLv():int
		{
			return _playerLv;
		}
		
		public function get playerExp():Number
		{
			return _playerExp;
		}
		
		public function get money():Number
		{
			return _money;
		}
		
		public function get gold():Number
		{
			return _gold;
		}
		
		public function get actPoint():int
		{
			return _actPoint;
		}
		
		public function get playerLife():int
		{
			return _playerLife;
		}
		
		public function set playerLv(value:int):void
		{
			if(_playerLv!=-1 && value>_playerLv)GU_Sound.instance.playCommSound("Body_Upgrade");
			_playerLv=value;
			this.touchObserve("playerLv");
			FlatInfo.playLv=value;
		}
		
		public function set playerExp(value:Number):void
		{
			_playerExp=value;
			if (GD_Reward && GD_Reward.rewardContainer)
			{
				_playerExp=playNowExp - int(GD_Reward.rewardContainer[4]);
			}
			if (_playerExp >= this.playerCurrentMaxExp)
			{
				M_Communication.instance.send(12006);
			}
			this.touchObserve("exp");
		}
		
		public function set money(value:Number):void
		{
			_money=value;
			if (GD_Reward && GD_Reward.rewardContainer)
			{
				_money=playNowMoney - int(GD_Reward.rewardContainer[2]);
			}
			this.touchObserve("money");
			FlatInfo.playMoney=value;
		}
		
		public function set gold(value:Number):void
		{
			_gold=value;
			if (GD_Reward && GD_Reward.rewardContainer)
			{
				_gold=playNowOMoney - int(GD_Reward.rewardContainer[3]);
			}
			this.touchObserve("gold");
		}
		
		public function set actPoint(value:int):void
		{
			_actPoint=value;
			if (GD_Reward && GD_Reward.rewardContainer)
			{
				_actPoint=playerNowAction - int(GD_Reward.rewardContainer[1]);
			}
			this.touchObserve("actPoint");
		}
		
		public function set playerLife(value:int):void
		{
			this.character.life=value;
			//_playerLife = value;
			//this.touchObserve("playerLife");
		}
		
		public function get centerLv():int
		{
			return _centerLv;
		}
		
		public function set centerLv(value:int):void
		{
			_centerLv=value;
			this.touchObserve("centerLv");
		}
		
		
		public function get attDam():Number
		{
			return 1;
		}
		
		public function get attType():int
		{
			return 1;
		}
		
		/**
		 *  人物攻击的范围  根据武器来
		 */
		public function get attRange():Number
		{
			return _attRange;
		}
		
		/**
		 *人物攻击方式 
		 */
		public function get attactType():String
		{
			return _attactType;
		}
		
		
		/**
		 * 治愈范围 
		 * @return 
		 */		
		public function get cureRange():Number
		{
			return 1;
		}
		
		/**
		 * 铲除范围 
		 * @return 
		 */		
		public function get collegeRange():Number
		{
			return 1;
		}
		
		/**
		 * 修理篱笆的范围
		 * @return
		 */
		public function get repairRange():Number
		{
			return 3;
		}
		
		public function get havenState():Boolean
		{
			return _havenState;
		}
		
		public function set havenState(value:Boolean):void
		{
			_havenState=value;
		}
		
		public function get playerViewID():String
		{
			return _playerViewID;
		}
		
		public function get mapData():GD_Map
		{
			return _mapData;
		}
		
		public function get character():GD_Character
		{
			return _character;
		}
		
		public function get items():Object
		{
			return _items;
		}
		
		public function get missions():Object
		{
			return _missions;
		}
		
		public function get storeBuildings():Object
		{
			return _storeBuildings;
		}
		
		/**
		 * 收藏物品存储器
		 * @return
		 */
		public function collectMissionArr(missionType:Number=21,taskStep:int=-1):Array
		{
			var s:Array=_collectMissionArr;
			var tmpArr:Array=[];
			var len:int=_collectMissionArr.length;
			for (var i:int=0; i < len; i++)
			{
				var gd:GD_Mission_Collection=_collectMissionArr[i] as GD_Mission_Collection;
				if(taskStep!=-1)
				{
					if (gd.collectMissionType == missionType && taskStep>=gd.collectTaskStep)
					{
						tmpArr.push(gd);
					}
				}else{
					if (gd.collectMissionType == missionType)
					{
						tmpArr.push(gd);
					}
				}
			}
			return tmpArr;
		}
		
		
		/**
		 * 当前玩家经验上限
		 */
		public function get playerCurrentMaxExp():Number
		{
			return _playerCurrentMaxExp;
		}
		
		/**
		 * @private
		 */
		public function set playerCurrentMaxExp(value:Number):void
		{
			_playerCurrentMaxExp=value;
			this.touchObserve("exp");
		}
		
		/**
		 * 玩家当前行动了上限
		 */
		public function get playCurrentMaxActPoint():int
		{
			return _playCurrentMaxActPoint;
		}
		
		/**
		 * @private
		 */
		public function set playCurrentMaxActPoint(value:int):void
		{
			_playCurrentMaxActPoint=value;
			this.touchObserve("actPoint");
		}
		
		public function set playerName(value:String):void
		{
			_playerName=value;
		}
		
		public function set playerViewID(value:String):void
		{
			_playerViewID=value;
		}
		
		public function set playerJob(value:int):void
		{
			_playerJob=value;
		}
		
		public function set playerSex(value:String):void
		{
			_playerSex=value;
		}
		
		/**
		 * 剩余恢复体力的时间  以秒为单位
		 */
		public function get powerTime():Number
		{
			return _powerTime;
		}
		
		/**
		 * @private
		 */
		public function set powerTime(value:Number):void
		{
			_powerTime=value;
			this.touchObserve("powerTimer");
		}
		
		/**
		 * 监听 行动力的时间  是否关闭  true-代表关闭(没有倒计时在显示) ；false-代表打开（有倒计时在显示）
		 */
		public function get closeTimerLister():Boolean
		{
			return _closeTimerLister;
		}
		
		
		/**
		 * @private
		 */
		public function set closeTimerLister(value:Boolean):void
		{
			_closeTimerLister=value;
		}
		
		/**
		 * 玩家拥有的所有武器 (处理装备上去的)
		 * @return
		 *
		 */
		public function get weapons():Object
		{
			return _weapons;
		}
		
		/**
		 * 围墙等级
		 * @return
		 */
		public function get wallLv():int
		{
			return _wallLv;
		}
		
		public function set wallLv(value:int):void
		{
			_wallLv=value;
		}
		
		/**
		 * 已经装备好的武器
		 * @return
		 */
		public function get selectWeapons():Object
		{
			return _selectWeapons;
		}
		
		public function set selectWeapons(value:Object):void
		{
			_selectWeapons=value;
		}
		
		public function set weapons(value:Object):void
		{
			_weapons=value;
		}
		
		
		
		
		/**
		 * 玩家当前武器
		 */
		public function get currentWeapon():String
		{
			return _currentWeapon;
		}
		
		/**
		 * @private
		 */
		public function set currentWeapon(value:String):void
		{
			//如果是新手 则  选取武器里面加入 初始化武器    （看后台是否有返回）
			//改变射程跟攻击方式
			var gdWeapon:GD_Weapon=this.getCurrentWeaponByType(Number(value));
			this._attRange=gdWeapon.weaponRange;
			switch(gdWeapon.weaponAttack)
			{
				case 1:
					this._attactType="attack";
					break;
				case 2:
					this._attactType="attack_throw";
					break;
				case 3:
					this._attactType="attack_short";
					break;
			}
			_currentWeapon=value;
			this.character.currentOwnWeapon=value;
		}
		
		/**
		 * 在好友家的友情行动力 
		 */
		public function get friendAct():Number
		{
			return _friendAct;
		}
		
		/**
		 * @private
		 */
		public function set friendAct(value:Number):void
		{
			_friendAct = value;
			this.touchObserve("friendAct");
		}
		
		/**
		 * 是否是新手  0老玩家  1是新手 
		 * @return 
		 */		
		public function get isNew():int
		{
			return _isNew;
		}
		
		public function set isNew(value:int):void
		{
			_isNew = value;
		}
		
		
		//***************返回家的功能************************
		
		/**
		 * 向后台发送回家的命令 
		 */		
		public function sendGoHomeComm():void
		{
			M_Communication.instance.send(128007);
		}
		
		private var listerTimer:Timer;
		
		/**
		 * 回家 
		 */		
		public function gotoMyHome(dataObj:Object):void
		{
			GV_Map.instance.release_GVMap();
			GV_Map.instance.reset();
			
			//newguide移除 回家的箭头
			GU_dealPower.instance.removeArrowForFriend();
			
			GD_AllFriends.instance.currentVisableFriend=null;
			
			//初始化地图上面的 杂物 僵尸 建筑等
			GD_Player.instance.character.characterState=0;
			this._mapData=GD_Map.creat(dataObj.wallsAry, dataObj.buildingsAry, dataObj.zombiesAry, dataObj.sickMansAry, dataObj.sundriesAry);
			this._mapData.creatMap();
			
			GV_Map.instance.creatCharacter(this.character, true);
			
			//初始化雇佣好友
			//			GD_AllFriends.instance.goHomeCreateHiredFriend();
			GD_AllFriends.instance.createHiredFirends(GD_AllFriends.instance.getHiredFriendArr());
			
			
			//行动力面板
			this.touchObserve("isInHome");
			
			
			//把拜访的好友清空
			
			GD_AllFriends.instance.currentVisableFriendId=0;
			VP_Main.instance.interfaceUI["visibleFriendId"]	=	-1;
			
			listerTimer=new Timer(1000,3);
			listerTimer.addEventListener(TimerEvent.TIMER_COMPLETE,completeTimerHalder);
			listerTimer.start();
			
			GD_HavenWall.setIsHome(true);
			
		}
		
		private function completeTimerHalder(evt:TimerEvent):void
		{
			listerTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,completeTimerHalder);
			listerTimer=null;
			//以后可以在此处加入移除 播放动画的代码
			GV_Map.instance.addListener();
			VP_OpenWinView.instance.closeWin();
			//new guide
			//			GU_dealPower.instance.removeArrowForFriend();
			GU_dealPower.instance.isInFriendHome=false;
			GU_dealPower.instance.clickFriendFrame();
			
			this.tweenCenter();
		}
		
		/**
		 * QQ黄钻等级(0 表示不是黄钻 1 表示一级黄钻  101表示 年黄钻一级  102 表示年 黄钻二级)
		 */
		public function get qqVipId():int
		{
			return _qqVipId;
		}
		
		/**
		 * @private
		 */
		public function set qqVipId(value:int):void
		{
			_qqVipId = value;
			FlatInfo.qqVipId=value;
		}
		
		/**
		 * 是否领取QQ新手礼包 (1为没有，0为领取)
		 */
		public function get isGetNewqqGift():int
		{
			return _isGetNewqqGift;
		}
		
		/**
		 * @private
		 */
		public function set isGetNewqqGift(value:int):void
		{
			_isGetNewqqGift = value;
		}
		
		/**
		 * 是否领取QQ每日礼包 (1为没有，0为领取)
		 */
		public function get isGetDayqqGift():int
		{
			return _isGetDayqqGift;
		}
		
		/**
		 * @private
		 */
		public function set isGetDayqqGift(value:int):void
		{
			_isGetDayqqGift = value;
		}
		
		/**
		 * 进行建筑兑换的物品 数量 
		 */
		public function get exchangeBuildItemNum():int
		{
			return _exchangeBuildItemNum;
		}
		
		/**
		 * @private
		 */
		public function set exchangeBuildItemNum(value:int):void
		{
			_exchangeBuildItemNum = value;
			this.touchObserve("exItemNum");
		}
		
		/**
		 * 我的建筑对象  支持我在好友家时  任务拥有建筑的功能
		 */
		public function get myBuildObj():Object
		{
			return _myBuildObj;
		}
		
		/**
		 * @private
		 */
		public function set myBuildObj(value:Object):void
		{
			_myBuildObj = value;
		}
		
		/**
		 * 在线礼包领取时间 如果为0  则领取次数完毕  其余的都为倒计时时间  
		 */
		public function get onlineMinute():int
		{
			return _onlineMinute;
		}
		
		/**
		 * @private
		 */
		public function set onlineMinute(value:int):void
		{
			_onlineMinute = value;
			this.touchObserve("onLineGift");
		}
		
		/**
		 * 玩家初始化速度 
		 */
		public function get speed():int
		{
			return _speed;
		}
		
		/**
		 * @private
		 */
		public function set speed(value:int):void
		{
			_speed = value;
			if(null==this.character)return;
			this.character.playSpeed=value;
			//			this.touchObserve("palySpeed");
		}
		
		/**
		 * 加速影响的时间  剩余时间
		 */
		public function get speedTime():int
		{
			return _speedTime;
		}
		
		/**
		 * @private
		 */
		public function set speedTime(value:int):void
		{
			_speedTime = value;
			GU_DealPlaySpeed.instance.speedTime=value;
			
		}
		
		
		/**
		 * @private
		 */
		public function set playPower(value:String):void
		{
			_playPower = value;
			if(null!=value)
			{
				var tmpArr:Array=value.split(",");
				for(var i:int=0;i<tmpArr.length;i++)
				{
					this.playPowerObj[tmpArr[i]]=tmpArr[i];
				}
			}
		}
		
		/**
		 * 玩家权限对象 
		 */
		public function get playPowerObj():Object
		{
			return _playPowerObj;
		}
		
		/**
		 * @private
		 */
		public function set playPowerObj(value:Object):void
		{
			_playPowerObj = value;
		}

		/**
		 *用来装载新武器的 对象 用来实现  得到新武器时 弹框的问题 
		 */
		public function get addNewWeapons():Object
		{
			return _addNewWeapons;
		}

		/**
		 * @private
		 */
		public function set addNewWeapons(value:Object):void
		{
			_addNewWeapons = value;
		}

	}
}